﻿using DatabaseUserTest.Controller;
using DatabaseUserTest.DB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DatabaseUserTest.Model;

namespace DatabaseUserTest
{
    public partial class OrderWindow : Form
    {
        DestinationCTRL destCtrl = new DestinationCTRL();
        DBDestination dbdest = new DBDestination();
        RouteCTRL routeCtrl  = new RouteCTRL();
        DBPlane dbPlane = new DBPlane();
        DijkstraCTRL dijkstraCtrl = new DijkstraCTRL();

        public OrderWindow()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            LoadData();
        }

        private void LoadData()
        {
            List<Destination> destlist = destCtrl.FindAllDestinations();

            foreach (Destination item in destlist)
            {
                fromComboBox.Items.Add(item.Name);
            }
            foreach (Destination item in destlist)
            {
                toComboBox.Items.Add(item.Name);
            }
            for (int i = 1; i <= 4; i++)
            {
                seatComboBox.Items.Add(i);
            }

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //dbPlane.FillHerUp();
            if (fromComboBox.SelectedItem == toComboBox.SelectedItem)
            {
                label3.Text = "text her";
            }
            else
            {

                if (routeCtrl.FindRoute(fromComboBox.Text,toComboBox.Text) == null)
                {
                    if (firstClassCheckBox.Checked)
                    {
                        if (dijkstraCtrl.CalculateShortestPath(fromComboBox.Text, toComboBox.Text, 1, dateTimePicker1.Value, seatComboBox.SelectedIndex+1, true).BestTotalCost != 0)
                        {
                            CompleteRoute completeRoute = dijkstraCtrl.CalculateShortestPath(fromComboBox.Text, toComboBox.Text, 1, dateTimePicker1.Value, seatComboBox.SelectedIndex+1, true);
                            label3.Text = completeRoute.BestAllDestinations + " :) " + completeRoute.BestTotalCost;
                        }
                        else
                        {
                            label3.Text = "Not possible mein freund :(";
                        }
                        
                    }
                    
                }
                else
                {
                    routeCtrl.FindRoute(fromComboBox.Text, toComboBox.Text);
                }

            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void seatComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
